package com.igeek.d0606;

import java.io.*;
import java.lang.invoke.VarHandle;

/**
 * @Author: zhiyu
 * @Date:18:20
 * @DESC:
 */
public class Test2 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        fileInputByByte();//472
//        copyByByte();//115
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
    public static void fileInputByByte(){
        try (
                FileInputStream fis = new FileInputStream("D:\\桌面\\极客营\\2javase\\视频\\1 面向对象和面向过程的区别与联系.mp4");
                FileOutputStream fos = new FileOutputStream("D:\\copyTest\\test1.mp4")
        ){
            byte[] bys = new byte[1024];
            int len;
            while ((len = fis.read(bys)) != -1) {
                fos.write(bys, 0, len);
            }
            fos.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static void copyByByte() {
        try (
                FileInputStream fis = new FileInputStream("D:\\桌面\\极客营\\2javase\\视频\\1 面向对象和面向过程的区别与联系.mp4");
                BufferedInputStream bis = new BufferedInputStream(fis);
                FileOutputStream fos = new FileOutputStream("D:\\copyTest\\test2.mp4");
                BufferedOutputStream bos = new BufferedOutputStream(fos);
        ){
            byte[] bytes = new byte[1024];
            int i ;
            while((i=bis.read(bytes))!=-1){
                bos.write(bytes,0,i);
            }
            bos.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
